# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=libsndfile
pkgver=1.2.0
pkgrel=1
pkgdesc="A C library for reading and writing files containing sampled audio data"
arch=(x86_64)
url="https://libsndfile.github.io/libsndfile/"
license=(LGPL2.1)
depends=(glibc)
makedepends=(
  alsa-lib
  cmake
  flac
  lame
  libogg
  libvorbis
  mpg123
  opus
  python
  sqlite
)
optdepends=('alsa-lib: for sndfile-play')
provides=(libsndfile.so)
source=(https://github.com/$pkgname/$pkgname/releases/download/$pkgver/$pkgname-$pkgver.tar.xz{,.asc})
sha512sums=('c0dee6b33cd3c619aa13ec2854a5480e826640ca98a438758346194e83752af576a39f9de118824f0d0c61288632d87b489dc5793c025296e0f15564d87ca12a'
            'SKIP')
b2sums=('cb13fde9b9f44c6279a9ee7741457824eb41fc17261bf9c669d757e9e506eba2c3d4ad259e4625b8a11c82308188cc19f7399e9d1fc0299a3a11794e4b653e47'
        'SKIP')
validpgpkeys=(
  '6A91A5CF22C24C99A35E013FCFDCF91FB242ACED'  # Erik de Castro Lopo <erikd@mega-nerd.com>
  '9B1CFD2E92239C4B288E025F9D0D1F1CCB35FF8C'  # evpobr evpobr@gmail.com
  '31D95CAB6D80D262244A1750A47620E801E47E95'  # David Seifert soap@gentoo.org
)

build() {
  # tests can only be built with static libs
  cmake -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_BUILD_TYPE=None \
        -Wno-dev \
        -B build-test \
        -S $pkgname-$pkgver
  make VERBOSE=1 -C build-test

  cmake -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_BUILD_TYPE=None \
        -DBUILD_SHARED_LIBS=ON \
        -DENABLE_EXTERNAL_LIBS=ON \
        -DENABLE_MPEG=ON \
        -Wno-dev \
        -B build \
        -S $pkgname-$pkgver
  make VERBOSE=1 -C build
}

check() {
  make test -C build-test
}

package() {
  depends+=(
    flac libFLAC.so
    lame libmp3lame.so
    libogg libogg.so
    libvorbis libvorbis.so libvorbisenc.so
    mpg123 libmpg123.so
    opus libopus.so
  )

  make DESTDIR="$pkgdir" install -C build
  install -vDm 644 $pkgname-$pkgver/{AUTHORS,ChangeLog,README} -t "$pkgdir/usr/share/doc/$pkgname"
}
